#include "headfile.h"
#include "SEEKFREE_18TFT.h"
#include "TFT.h"
#include "BMP.h"

#if _USE_LCD
#define LINE_MAX 8
#elif _USE_IPS
#define LINE_MAX 8
#else
#define LINE_MAX 4                                           //一页能显示的总行数 OLED为4 LCD横向为8 竖向为10
#endif

signed char g_pageNum = 1;                                   //当前所在页
signed char g_lineNum = 1;                                   //当前所在行
signed char g_pageCount = 0;
signed char g_lineCount = 0;
signed char g_pageMax = 0;								     //页面总数
signed char g_lineMax = 0;                                   //当前页变量的个数

int8 g_lineLock = 0;                                 		 //锁定标志

signed char g_plusFlg = 0;                                   //加法标志
signed char g_minisFlg = 0;                                  //减法标志
signed char g_imgFlg = 0;

signed char g_Rate = 0;                                      //倍率指数 方便加减
float g_addValue = 1;                                        //倍率
signed char g_picture_show = 0;
signed char g_explore_page = 0;								//调节曝光功能页

int tmp_int1=1283;
char tmp_char1=12;
float tmp_float1=234;
    
int tmp_int2=12;
char tmp_char2=-12;
float tmp_float2=-90.08;

unsigned char Cursor[][16] =

{
#if _USE_LCD || _USE_IPS
	{0x00,0x00,0x00,0x02,0x04,0x08,0x10,0x20,0x40,0x20,0x10,0x08,0x04,0x02,0x00,0x00},//>
	{0x00,0x00,0x00,0x05,0x0A,0x14,0x28,0x50,0xA0,0x50,0x28,0x14,0x0A,0x05,0x00,0x00}//》
#else
	{0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00},//>
	{0x10,0x20,0x40,0x90,0x20,0x40,0x80,0x00,0x10,0x08,0x04,0x12,0x09,0x04,0x02,0x01}//》
#endif
};


//-------------------------------------------------------------------------------------------------------------------
//  @brief      显示光标
//  @param      void
//  @return     void		
//  @note            
//-------------------------------------------------------------------------------------------------------------------
void Dis_Cursor(unsigned char Position, signed char Number)
{
	uint8 i,j;
	uint8 temp;
	lcd_set_region(0,16*Position,7,16*Position+15);
	for(i=0;i<16;i++)
	{
		temp=Cursor[Number][i];
		for(j=0;j<8;j++)
		{
			if(temp&0x01)
				lcd_writedata_16bit(TFT_PENCOLOR);
			else 
				lcd_writedata_16bit(TFT_BGCOLOR);
			temp>>=1;
		}
	}
}


//=================================================================//
//  @brief      总钻风(灰度摄像头)液晶缩放显示函数
//  @param      *p     			图像数组地址
//  @param      width     	    图像宽度
//  @param      height     	    图像高度
//  @param      dis_width       图像显示宽度  1 -（TFT_X_MAX）
//  @param      dis_height      图像显示高度  1 -（TFT_Y_MAX）
//  @return     void
//  @since      v1.0
//  Sample usage:               lcd_displayimage032_zoom(mt9v03x_csi_image[0], MT9V03X_CSI_W, MT9V03X_CSI_H, 0, 0, 160, 120)//显示灰度摄像头 图像
//  @note       图像的宽度如果超过液晶的宽度，则自动进行缩放显示。这样可以显示全视野
//=================================================================//
void displayimage032_zoom(uint8* p, uint16 y_position, uint16 row_up, uint16 row_down, uint8 showeage,
                          int *LL, int *RL, int *ML, int ProSpect)
{
	int i, j;
	int offset = y_position - row_up;
	uint16 color = 0;
	uint16 temp = 0;

	for (i = row_up; i <= row_down; i++)
	{
		lcd_set_region(0, y_position, 160 - 1, y_position);		//坐标设置
//        Lcd_SetRegion(120-i,0,120-i,160-1);		//坐标设置
		for (j = 0; j < 160; j++)
		{
			temp = *(p + i * IMG_ROW / 120 * IMG_COL + j * (IMG_COL - 1) / (160 - 1));//读取像素点

			color = (0x001f & ((temp) >> 3)) << 11;
			color = color | (((0x003f) & ((temp) >> 2)) << 5);
			color = color | (0x001f & ((temp) >> 3));
			lcd_writedata_16bit(color);
		}
		y_position++;
	}
	if (showeage)
	{
		//showeage
		for (i = row_up; i < row_down; i++)
		{
			lcd_set_region(ML[i] * 159 / 188, i + offset, ML[i] * 159 / 188, i + offset);
			lcd_writedata_16bit(BLUE);
			lcd_set_region(LL[i] * 159 / 188, i + offset, LL[i] * 159 / 188, i + offset);
			lcd_writedata_16bit(GREEN);
			lcd_set_region(RL[i] * 159 / 188, i + offset, RL[i] * 159 / 188, i + offset);
			lcd_writedata_16bit(RED);
		}
		lcd_set_region(0, UP_EDGE + offset, 159, UP_EDGE + offset);
		for (i = 0; i < 160; ++i)
		{
			lcd_writedata_16bit(RED);
		}
		lcd_set_region(0, DOWN_EDGE + offset, 159, DOWN_EDGE + offset);
		for (i = 0; i < 160; ++i)
		{
			lcd_writedata_16bit(GREEN);
		}
		lcd_set_region(0, ProSpect + offset, 159, ProSpect + offset);
		for (i = 0; i < 160; ++i)
		{
			lcd_writedata_16bit(YELLOW);
		}
	}
}

//-------------------------------------------------------------------------------------------------------------------
//  @brief      向左翻页
//  @param      void
//  @return     void		
//  @note            
//-------------------------------------------------------------------------------------------------------------------
void PageNumberReduce(void)
{
	lcd_clear(TFT_BGCOLOR);
	g_pageNum--;
	if(g_pageNum<1)g_pageNum=g_pageMax;
	g_lineNum=1;
}

//-------------------------------------------------------------------------------------------------------------------
//  @brief      向右翻页
//  @param      void
//  @return     void		
//  @note            
//-------------------------------------------------------------------------------------------------------------------
void PageNumAdd(void)
{
	lcd_clear(TFT_BGCOLOR);
	g_pageNum++;
	if(g_pageNum>g_pageMax)g_pageNum=1;
	g_lineNum=1;
}

//-------------------------------------------------------------------------------------------------------------------
//  @brief      行数上移
//  @param      void
//  @return     void		
//  @note            
//-------------------------------------------------------------------------------------------------------------------
void LineNumReduce(void)
{
	g_lineNum--;
	if(g_lineNum<1)g_lineNum=g_lineMax;
}

//-------------------------------------------------------------------------------------------------------------------
//  @brief      行数下移
//  @param      void
//  @return     void		
//  @note            
//-------------------------------------------------------------------------------------------------------------------
void LineNumAdd(void)
{
	g_lineNum++;
	if(g_lineNum>g_lineMax)g_lineNum=1;
}


//-------------------------------------------------------------------------------------------------------------------
//  @brief      前往给定页
//  @param      int8 GivenPage,需要跳转的页码
//  @return     void		
//  @note            
//-------------------------------------------------------------------------------------------------------------------
void GotoGivenPage(char GivenPage)
{
	lcd_clear(TFT_BGCOLOR);

	if(GivenPage>0&&GivenPage<=g_pageMax)
		g_pageNum=GivenPage;
	else if(GivenPage>g_pageMax)
		g_pageNum=g_pageMax;
	else 
		g_pageNum=1;
	g_lineLock=0;
	g_lineNum=1;
}

//-------------------------------------------------------------------------------------------------------------------
//  @brief      插入一个页面
//  @param      需要显示的标题，当不需要显示标题时字符串写"\0"
//  @return     void		
//  @note            
//-------------------------------------------------------------------------------------------------------------------
void Insert_Page(signed char String[])
{
	g_pageCount++;
	
	if(g_pageMax<g_pageCount)
		g_pageMax=g_pageCount;
	
	if(g_pageNum==g_pageCount)
	{
		g_imgFlg=0;
		if(String!='\0')
		{
			Dis_Head(String);
		}
		g_lineMax=0;
	}
	g_lineCount=0;
}

//-------------------------------------------------------------------------------------------------------------------
//  @brief      插入字符变量
//  @param      在菜单中的位置 需要插入的变量名以及变量的地址
//  @return     void		
//  @note            
//-------------------------------------------------------------------------------------------------------------------
void Insert_Char(signed char String[], signed char* Number)
{
	char tmp_line;
	if(g_pageNum==g_pageCount)
	{
		g_lineCount++;

		if(g_lineMax<g_lineCount)
			g_lineMax=g_lineCount;
		
		if(g_lineNum<LINE_MAX)
		{
			tmp_line=g_lineCount;
			Dis_String(2*tmp_line-1,String);
			Dis_Int(2*tmp_line,*Number);
		}
		else
		{
			if (g_lineNum >= g_lineCount)
			{
				tmp_line = LINE_MAX - 1 + g_lineCount - g_lineNum;
				Dis_String(2 * tmp_line - 1, String);
				Dis_Int(2 * tmp_line, *Number);
			}
		}

		if (g_lineNum == g_lineCount)
		{
			if (g_plusFlg)
			{
				*Number += (int)g_addValue;
				g_plusFlg = 0;
			}
			else if (g_minisFlg)
			{
				*Number -= (int)g_addValue;
				g_minisFlg = 0;
			}
		}

	}
}
//-------------------------------------------------------------------------------------------------------------------
//  @brief      插入整形变量
//  @param      在菜单中的位置 需要插入的变量名以及变量的地址
//  @return     void		
//  @note            
//-------------------------------------------------------------------------------------------------------------------
void Insert_Int(signed char String[], signed int* Number)
{
	char tmp_line;
	if (g_pageNum == g_pageCount)
	{
		g_lineCount++;
		if (g_lineMax < g_lineCount) 
			g_lineMax = g_lineCount;

		if (g_lineNum < LINE_MAX)
		{
			tmp_line = g_lineCount;
			Dis_String(2 * tmp_line - 1, String);
			Dis_Int(2 * tmp_line, *Number);
		}
		else
		{
			if (g_lineNum >= g_lineCount)
			{
				tmp_line = LINE_MAX - 1 + g_lineCount - g_lineNum;
				Dis_String(2 * tmp_line - 1, String);
				Dis_Int(2 * tmp_line, *Number);
			}
		}

		if (g_lineNum == g_lineCount)
		{
			if (g_plusFlg)
			{
				*Number += (int)g_addValue;
				g_plusFlg = 0;
			}
			else if (g_minisFlg)
			{
				*Number -= (int)g_addValue;
				g_minisFlg = 0;
			}
		}
	}
}

//-------------------------------------------------------------------------------------------------------------------
//  @brief      插入浮点型变量
//  @param      在菜单中的位置(0~127) 需要插入的变量名以及变量的地址
//  @return     void		
//  @note            
//-------------------------------------------------------------------------------------------------------------------
void Insert_Float(signed char String[], float* Number)
{
	char tmp_line;

	if (g_pageNum == g_pageCount)
	{
		g_lineCount++;
		if (g_lineMax < g_lineCount)
			g_lineMax = g_lineCount;

		if (g_lineNum < LINE_MAX)
		{
			tmp_line = g_lineCount;
			Dis_String(2 * tmp_line - 1, String);
			Dis_Float(2 * tmp_line, *Number);
		}
		else
		{
			if (g_lineNum >= g_lineCount)
			{
				tmp_line = LINE_MAX - 1 + g_lineCount - g_lineNum;
				Dis_String(2 * tmp_line - 1, String);
				Dis_Float(2 * tmp_line, *Number);
			}
		}
		if (g_lineNum == g_lineCount)
		{
			if (g_plusFlg)
			{
				*Number += g_addValue;
				g_plusFlg = 0;
			}
			else if (g_minisFlg)
			{
				*Number -= g_addValue;
				g_minisFlg = 0;
			}
		}
	}
}

//=================================================================//
// @brief:  插入浮点型变量
// @param:  在菜单中的位置(0~127) 需要插入的变量名以及变量的地址
//@retirn:  void    
// @note: 
//=================================================================//
void Insert_VFloat(signed char String[], volatile float* Number)
{
	char tmp_line;

	if (g_pageNum == g_pageCount)
	{
		g_lineCount++;
		if (g_lineMax < g_lineCount) 
			g_lineMax = g_lineCount;

		if (g_lineNum < LINE_MAX)
		{
			tmp_line = g_lineCount;
			Dis_String(2 * tmp_line - 1, String);
			Dis_Float(2 * tmp_line, *Number);
		}
		else
		{
			if (g_lineNum >= g_lineCount)
			{
				tmp_line = LINE_MAX - 1 + g_lineCount - g_lineNum;
				Dis_String(2 * tmp_line - 1, String);
				Dis_Float(2 * tmp_line, *Number);
			}
		}
		if (g_lineNum == g_lineCount)
		{
			if (g_plusFlg)
			{
				*Number += g_addValue;
				g_plusFlg = 0;
			}
			else if (g_minisFlg)
			{
				*Number -= g_addValue;
				g_minisFlg = 0;
			}
		}
	}
}


//-------------------------------------------------------------------------------------------------------------------
//  @brief      重置补图参数
//  @param      void
//  @return     void		
//  @note            
//-------------------------------------------------------------------------------------------------------------------
void Init_CamVar()
{
	Forks_State=0;
	getA_Flag=0;
	getB_Flag=0;
	getC_Flag=0;
	CircleFlag=0;
	CircleState=0;
}



//=================================================================//
//  @brief:	    按键功能
//  @param: 	void
//  @return: 	void
//  @note: 
//=================================================================//
void Key_Function(void)
{
    if(!g_lineLock)
	switch(g_Key)
	{
		case 1:
		{
			//if(g_steer_open)
			g_drive_flag=!g_drive_flag;
			if(g_drive_flag)
			{
				CircleFlag=0;
				CircleState=0;
				Img_RampFlag=0;
				speed_type=1;
				if(g_camera_open)
					g_handle_open=1;
				g_steer_open=1;
			}
		}
		break;
		case 2:
			if(g_pageNum==1)
				g_steer_open=!g_steer_open;				//开舵机
			else
				LineNumReduce();		 			//行数上移
			break;
		case 3:
			lcd_init();
			if(g_pageNum==1)
				set_exposure_time(USART_5,exp_time);  		//曝光时间
			break;
		case 4:
			PageNumberReduce();						//向上翻页
			break;
		case 5:
			if(g_pageNum==1)
				g_handle_open=!g_handle_open;			//开补图
			else
				g_lineLock=1;						//进入数值修改
			break;
		case 6:
			PageNumAdd();							//向下翻页
			break;
		case 7:
                        // test_flag=!test_flag;
                        // if(test_flag<0)test_flag=0;
                        // else if(test_flag>1)test_flag=1;
						Init_CamVar();
			break;
		case 8:
			if(g_pageNum==1)
			{
				g_picture_show++;
				lcd_clear(TFT_BGCOLOR);
			}
			else
				LineNumAdd();						//行数下移
			break;
		case 9:
			SD_Gather_Gray_Picture120x188();         
			break; 									//采图
		default:
			break;
	}
	else
	{
		switch(g_Key)
		{
			case 1:
				// MyFlash_Write(0);    break;    			//写入FLASH
			case 2:		LineNumReduce();		break;		//行数上移
			case 3:		g_plusFlg=1;			break;		//数值加
			case 4:		g_Rate--;				break;		//减少倍率
			case 5:		g_lineLock=0;			break;		//退出数值修改
			case 6:		g_Rate++;				break;		//增加倍率
			case 7:								break;
			case 8:		LineNumAdd();			break;		//行数下移
			case 9:		g_minisFlg=1;			break;		//数值减
			default:							break;
		}
	}
	INTR_Keyboard_Init();
}

//=================================================================//
//  @brief:	    显示倍率和光标
//  @param: 	void
//  @return: 	void
//  @note: 
//=================================================================//
void Extra_Show(void)
{
	if(!g_imgFlg)
	{
		switch(g_lineNum)
		{
			case 1:
				Dis_Cursor(1,g_lineLock);
				lcd_showstr(0,2," ");
				lcd_showstr(0,3," ");
				lcd_showstr(0,4," ");
				lcd_showstr(0,5," ");
				lcd_showstr(0,6," ");
				lcd_showstr(0,7," ");
				break;
			case 2:
				Dis_Cursor(2,g_lineLock);
				lcd_showstr(0,1," ");
				lcd_showstr(0,3," ");
				lcd_showstr(0,4," ");
				lcd_showstr(0,5," ");
				lcd_showstr(0,6," ");
				lcd_showstr(0,7," ");
				break;
			case 3:
				Dis_Cursor(3,g_lineLock);
				lcd_showstr(0,1," ");
				lcd_showstr(0,2," ");
				lcd_showstr(0,4," ");
				lcd_showstr(0,5," ");
				lcd_showstr(0,6," ");
				lcd_showstr(0,7," ");
				break;
			case 4:
				Dis_Cursor(4,g_lineLock);
				lcd_showstr(0,1," ");
				lcd_showstr(0,2," ");
				lcd_showstr(0,3," ");
				lcd_showstr(0,5," ");
				lcd_showstr(0,6," ");
				lcd_showstr(0,7," ");
				break;
			case 5:
				Dis_Cursor(5,g_lineLock);
				lcd_showstr(0,1," ");
				lcd_showstr(0,2," ");
				lcd_showstr(0,3," ");
				lcd_showstr(0,4," ");
				lcd_showstr(0,6," ");
				lcd_showstr(0,7," ");
				break;
			case 6:
				Dis_Cursor(6,g_lineLock);
				lcd_showstr(0,1," ");
				lcd_showstr(0,2," ");
				lcd_showstr(0,3," ");
				lcd_showstr(0,4," ");
				lcd_showstr(0,5," ");
				lcd_showstr(0,7," ");
				break;
			default:
				Dis_Cursor(7,g_lineLock);
				lcd_showstr(0,1," ");
				lcd_showstr(0,2," ");
				lcd_showstr(0,3," ");
				lcd_showstr(0,4," ");
				lcd_showstr(0,5," ");
				lcd_showstr(0,6," ");
				break;
		}
	}
	switch(g_Rate)
	{
		case -4:		g_Rate=3;				break;
		case -3:		g_addValue=0.001;		break;
		case -2:		g_addValue=0.01;		break;
		case -1:		g_addValue=0.1;			break;
		case 0:			g_addValue=1;			break;
		case 1:			g_addValue=10;			break;
		case 2: 		g_addValue = 100;     	break;
		case 3: 		g_addValue = 1000;     	break;
		case 4: 		g_Rate = -3;           	break;
		default: 		g_Rate = 0;            	break;
	}
    if(g_Rate>=0)
    {
        lcd_showchar(144, 0, ' ');
		OLED_Write_Int(152,0,g_Rate);
    }
    else
        OLED_Write_Int(144,0,g_Rate);
}

//=================================================================//
//  @brief:	    菜单主体显示 包括变量显示与图像显示
//  @param: 	void
//  @return: 	void
//  @note: 
//=================================================================//
extern int speed_sum;
void Main_Show(void)
{
	g_pageCount=0;


	//图像页
//	Insert_Img("Display",DisplayImage)
	Insert_Page("Display");
	if(g_pageNum==1)
	{
		displayimage032_zoom(image[0], 64, 10, 70, 1,LL,RL,ML,ProSpect);
		switch (g_picture_show)
		{
		case 0:
			g_picture_show = 1;
		break;
		// case 1:
		// 	Dis_Float(2, imu_data.pit);
		// 	Dis_Float(4, imu_data.rol);
		// 	Dis_Float(6, imu_data.yaw);
		// 	Dis_Float(1, sensor.Gyro_deg.x);
		// 	Dis_Float(3, sensor.Gyro_deg.y);
		// 	Dis_Float(5, sensor.Gyro_deg.z);
		// 	break;
		case 3:      //调镜头信息页
			Dis_Int(1, ML[70]);
			Dis_Int(2, ML[60]);
			Dis_Int(3, ML[50]);
			Dis_Int(4, ML[40]);
		break;
		// case 4:
		// 	Dis_Int(1, ML[ProSpect]);
		// 	Dis_Int(3, Error_1);
		// 	Dis_Int(5, ErrorFlag);
        //     Dis_Int(2, lCurSpeed);
        //     Dis_Int(4, rCurSpeed);
		// 	break;
		case 2:
			Dis_Int(1, CircleFlag);
			Dis_Int(2, CircleState);
		break;

		case 1:
			Dis_Int(1, Forks_State);
			Dis_Int(2, getA_Flag);
			Dis_Int(3, getB_Flag);
			Dis_Int(4, getC_Flag);
			Dis_Int(5, Error_1);
			Dis_Int(6, SteerDuty);
		break;

		case 4:
			Dis_Int(1,233);
			Dis_Int(2,ind_left);
			Dis_Int(3,ind_mid);
			Dis_Int(4,ind_right);
		break;
		default:
			g_picture_show = 1;
		break;
		}
//		// Dis_Int(1,ML[70]);
//		// Dis_Int(2,ML[60]);
//		// Dis_Int(3,ML[50]);
//		// Dis_Int(4,ML[40]);
//        ;
	}

	// Insert_Page("TestPage1");
    // Insert_Char("g_key",&g_Key);
    // Insert_Char("g_lineNum",&g_lineNum);
    // Insert_Char("g_pagenum",&g_pageNum);
    // Insert_Int("tmp_int1",&tmp_int1);
    // Insert_Char("tmp_char1",&tmp_char1);
    // Insert_Float("tmp_float1",&tmp_float1);

    // Insert_Page("TestPage2");
    // Insert_Char("g_key",&g_Key);
    // Insert_Char("g_lineNum",&g_lineNum);
    // Insert_Char("g_pagenum",&g_pageNum);
    // Insert_Int("tmp_int2",&tmp_int2);
    // Insert_Char("tmp_char2",&tmp_char2);
    // Insert_Float("tmp_float2",&tmp_float2);
	Insert_Page("QuickChange");
//         Insert_Char("test_flag",&test_flag);
	Insert_Char("DriveFlag",&g_drive_flag);
	Insert_Char("SteerFlag",&g_steer_open);
	Insert_Float("pmax", &p_max);
	Insert_Float("pmin", &p_min);
    Insert_Float("spdK1",&speed_k1);
//	Insert_Float("SteerP", &Steer_P);                    //方向控制P
	Insert_Float("SteerD", &Steer_D);
	Insert_Int("ProSpect", &ProSpect);              //摄像头前瞻
	Insert_Float("CI_P", &Steer_P_CI);
//	Insert_Int("SpdExp1", &spdExp1);                 //实际速度
	Insert_Int("SpdBasic", &spdBas1);
	Insert_Int("SpeedRow", &SpeedRow);
        
    Insert_Page("QuickWatch1");
    Insert_Int("CurSpeed",&CurSpeed);
    Insert_Int("lCurSpeed",&lCurSpeed);
    Insert_Int("rCurSpeed",&rCurSpeed);
	Insert_Float("speedp", &g_speed_p);                    //方向控制P
	Insert_Float("speedI", &g_speed_i);
	Insert_Int("SpdExp1", &spdExp1);                 //实际速度
	Insert_Int("SpdExp2", &spdExp2);
//	Insert_Int("SpeedRow", &SpeedRow);	
	Insert_Page("CircleIsland");
    Insert_Char("CircleFlag",&CircleFlag);
    Insert_Char("CircleState",&CircleState);
    Insert_Float("Angle",&sensor.Gyro_deg.z);
	// Insert_Float("speedp", &g_speed_p);                    //方向控制P
	// Insert_Float("speedI", &g_speed_i);
	// Insert_Int("SpdExp1", &spdExp1);                 //实际速度
	// Insert_Int("SpdExp6", &spdExp6);


	// Insert_Page("QuickWatch2");
    // Insert_Int("Left_Ind",&ind_left);
    // Insert_Int("Mid_Ind",&ind_mid);
    // Insert_Int("Right_Ind",&ind_right);


	Insert_Page("Steer_PID");
	Insert_Char("Steer_Open",&g_steer_open);
	Insert_Int("SDSet", &SteerDutySet);
	Insert_Int("SteerDuty",&SteerDuty);
	Insert_Float("p_max",&p_max);
	Insert_Float("p_min",&p_min);
	Insert_Float("Steer_P_CI",&Steer_P_CI);
//	Insert_Float("Steer_P_Cross",&Steer_P_Cross);
	Insert_Float("Steer_P",&Steer_P);
	Insert_Float("Steer_D",&Steer_D);
	Insert_Int ("ERROR1", &Error_1);
	Insert_Int ("ERROR2",&Error_2);
	// Insert_Float("P",&steerC.p);
	// Insert_Float("D",&steerC.d);
	// Insert_Int("steer.duty",&steerC.steer_duty);

	Insert_Page("Speed");
	Insert_Int("CurSpeed",&CurSpeed);
	Insert_Int("leftSpdOut",&leftSpeedOut);
	Insert_Int("rightSpdOut",&rightSpeedOut);
	Insert_Int("KDet", &KDet);
	Insert_Int("spdExp",&spdExp);
	Insert_Int("spdExp1",&spdExp1);
	Insert_Int("spdExp2",&spdExp2);
//	Insert_Int("spdExp3",&spdExp3);
	Insert_Int("SpdBas1", &spdBas1);				//平跑基准速度
	Insert_Int("SpdBas2", &spdBas2);
	Insert_Float("SpeedP", &g_speed_p);             //速控P
	Insert_Float("SpeedI", &g_speed_i);             //速控I

	Insert_Page("Camera");
	Insert_Int("exp_time", &exp_time);
	Insert_Int("HighTH", &HighThreshold);
	Insert_Int("LowTH", &LowThreshold);
	Insert_Int("Light", &LightThreshold);
	Insert_Char("exp_page", &g_explore_page);
        
        Insert_Page("Openmv");
	Insert_Char("OpenmvStatus", &OpenmvStatus);
        Insert_Char("OpenmvData", &OpenmvData);
        Insert_Char("OpenmvOrder",&OpenmvOrder);
        Insert_Char("OpenmvCmd",&OpenmvCmd);
	// Insert_Int("spdExp1",&spdExp1);
	// Insert_Int("spdExp2",&spdExp2);
	// Insert_Int("spdExp3",&spdExp3);
	// Insert_Int("spdExp4",&spdExp4);
	// Insert_Int("spdExp5",&spdExp5);
	// Insert_Int("spdExp6",&spdExp6);
	// Insert_Int("spdExp7",&spdExp7);

}
//=================================================================//
//  @brief:	    摄像头调节曝光时间
//  @param: 	void
//  @return: 	void
//  @note: 
//=================================================================//
void ExploreTime(void)
{
	static unsigned char DispPicture = 0;	//显示整幅图像
	static unsigned char DispEdge = 1;		//显示边缘
	static signed char AddMul = 0;
	static unsigned char AddValue = 1;
	if(g_explore_page>1)
		g_explore_page=1;
	CannyEdge();
	//displayimage032(image[0]);
	displayimage032_zoom(image[0], 64, 10, 70, 1,LL,RL,ML,ProSpect);
	if (DispEdge)
	{
		unsigned char* p = ImageEdge[0];
		for (int i = 10; i <= 70; i++)
		{
			for (int j = 0; j < 160; j++)
			{
				unsigned char temp = *(p + i * IMG_ROW / 120 * IMG_COL + j * (IMG_COL - 1) / (160 - 1));//读取像素点
				if (HIGH_TH == temp)
				{
					lcd_set_region(j, i + 54, j, i + 54);		//坐标设置
					lcd_writedata_16bit(BLUE);
				}
			}
		}
	}
	//display
	Dis_String(1, "exp_time"); Dis_Int(2, exp_time);
	Dis_String(3, "ave_gray"); Dis_Int(4, LightThreshold);
	OLED_Write_Int(0, 152, AddMul);
	if (0 == AddMul) AddValue = 1;
	else if (1 == AddMul) AddValue = 10;
	else if (2 == AddMul) AddValue = 100;
	switch (g_Key)
	{
	case 1:
//		MyFlash_Write(0);
		break;
	case 3:
		exp_time += AddValue;
		break;
	case 4:
		AddMul--;
		if (AddMul < 0)AddMul = 2;
		break;
	case 6:
		AddMul++;
		if (AddMul > 2) AddMul = 0;
		break;
	case 5:
		set_exposure_time(USART_5,exp_time);
		break;
	case 8:
		g_explore_page = 0;
		g_pageNum = 1;
		g_lineNum = 1;
		lcd_clear(TFT_BGCOLOR);
		break;
	case 9:
		exp_time -= AddValue;
		break;
	default:
		break;
	}
	INTR_Keyboard_Init();
}

//=================================================================//
//  @brief:	    菜单主体显示 包括变量显示与图像显示
//  @param: 	void
//  @return: 	void
//  @note: 
//=================================================================//
void Menu(void)
{
	//g_Key = Key_Check();
	Key_Function();
	if (1)//!Drive_Flag)
	{
		if (g_explore_page) 
			ExploreTime();
		else
		{
			Extra_Show();
			Main_Show();
		}
	}
}
